using System;
using System.Collections.Generic;
using System.Text;
using System.Drawing;
using System.Xml.Serialization;
using GraphAlgsPresentation.Core;
using System.ComponentModel;

namespace GraphAlgsPresentation.ScriptLibrary
{
    /// <summary>
    /// Provides a change text back color command
    /// </summary>
    [Serializable]
    public class ChangeTextBackColor : Command
    {
        private int _index;

        /// <summary>
        /// Gets or sets the index.
        /// </summary>
        /// <value>The index.</value>
        public int Index
        {
            get { return _index; }
            set { _index = value; }
        }

        private Color _newColor;

        /// <summary>
        /// Gets or sets the color.
        /// </summary>
        /// <value>The color.</value>
        [XmlIgnore]
        public Color Color
        {
            get { return _newColor; }
            set { _newColor = value; }
        }

        /// <summary>
        /// Gets or sets the color of the XML.
        /// </summary>
        /// <value>The color of the XML.</value>
        [Browsable(false)]
        public string XmlColor
        {
            get { return XmlDataConverter.SerializeColor(this.Color); }
            set { this.Color = XmlDataConverter.DeserializeColor(value); }
        }

        private Color oldColor;
        /// <summary>
        /// Gets or sets the old color.
        /// </summary>
        /// <value>The old color.</value>
        [XmlIgnore]
        [Browsable(false)]
        public Color OldColor
        {
            get { return oldColor; }
            set { oldColor = value; }
        }

        /// <summary>
        /// Initializes a new instance of the <see cref="ChangeTextBackColor"/> class.
        /// </summary>
        public ChangeTextBackColor()
        {
        }

        /// <summary>
        /// Initializes a new instance of the <see cref="ChangeTextBackColor"/> class.
        /// </summary>
        /// <param name="index">The line's index.</param>
        /// <param name="color">The color.</param>
        public ChangeTextBackColor(int index, Color color)
        {
            this.Index = index;
            this.Color = color;
        }

        /// <summary>
        /// Runs this instance.
        /// </summary>
        public override void Run()
        {
            oldColor = this.Context.CommentControl.Lines[Index].BackColor;
            this.Context.CommentControl.SetBackColor(this.Index, this.Color);
        }

        /// <summary>
        /// Undoes this instance.
        /// </summary>
        public override void Undo()
        {
            this.Context.CommentControl.SetBackColor(this.Index, this.OldColor);
        }
    }
}
